package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.service.DianSerivice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author 31629
 * @date 2025年09月06日 11:01
 */
@RestController
public class DianController {
   @Autowired
    private DianSerivice dianSerivice;
   @RequestMapping("s1")
   public JSONObject select1(){
       JSONObject rest = new JSONObject();
       rest.put("status",0);
       rest.put("msg","");
       JSONArray data = new JSONArray();
       rest.put("data",data);

       List<Map<String, Objects>> maps = dianSerivice.select1();
       for (Map<String, Objects> map : maps) {
           JSONObject row = new JSONObject();
           row.put("name",map.get("name"));
           row.put("value",map.get("cta"));
           data.add(row);
       }
       return  rest;
   }

    @RequestMapping("s2")
    public JSONObject select2(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONObject data = new JSONObject();
        rest.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();

        data.put("categories",categories);
        data.put("series",series);

        JSONObject series_1 = new JSONObject();
        series_1.put("name","品牌交易额");
        series.add(series_1);
        JSONArray row = new JSONArray();
        List<Map<String, Objects>> maps = dianSerivice.select2();
        for (Map<String, Objects> map : maps) {
           categories.add(map.get("name"));
           row.add(map.get("cta"));
           series_1.put("data",row);
        }
        return  rest;
    }

    @RequestMapping("s3")
    public JSONObject select3(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        List<Map<String, Objects>> maps = dianSerivice.select3();
        Map<String, Objects> map = maps.get(0);
        rest.put("data",map.get("cta"));
        return  rest;
    }

    @RequestMapping("s4")
    public JSONObject select4(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONObject data = new JSONObject();
        rest.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();

        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject col1 = new JSONObject();
        col1.put("name","名称");
        col1.put("id","name");

        JSONObject col2 = new JSONObject();
        col2.put("name","订单金额");
        col2.put("id","cta");

        columns.add(col1);
        columns.add(col2);
        List<Map<String, Objects>> maps = dianSerivice.select4();
        for (Map<String, Objects> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            rows.add(row);
        }
        return  rest;
    }
}
